Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function_return_linter() #1569

Merged
merged 6 commits into from
Sep 30, 2022
Merged

New function_return_linter() #1569

merged 6 commits into from
Sep 30, 2022

Conversation

MichaelChirico
Copy link
Collaborator

Part of #884

NEWS.md Outdated Show resolved Hide resolved
@IndrajeetPatil IndrajeetPatil added this to the 3.0.2 milestone Sep 30, 2022
@AshesITR
Copy link
Collaborator

Wondering whether we should centralize this to return_linter instead of making this a separate linter. WDYT?

@MichaelChirico
Copy link
Collaborator Author

Good point -- do we have any other linters in the package yet under this umbrella?

Smaller point -- what about function_return_linter(), is that too much?

@MichaelChirico
Copy link
Collaborator Author

Just glancing over the list, I also see we could put this under assignment_linter as well. But I the emphasis here is much more on the return() side, so sticking with that.

@IndrajeetPatil IndrajeetPatil changed the title New return_assignment_linter New function_return_linter() Sep 30, 2022
Comment on lines +37 to +45
expect_lint(
trim_some("
foo <- function(x) {
return(x <<- x + 1)
}
"),
lint_msg,
linter
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add this one for the sake of completeness?

library(lintr)

lint(
  text = "foo <- function(x) {
        return(x + 1 ->> x)
      }
    ",
  linters = function_return_linter()
)
#> <text>:2:16: warning: [function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether.
#>         return(x + 1 ->> x)
#>                ^~~~~~~~~~~

Created on 2022-09-30 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants